package com.zhangck.bos2_0.Service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhangck.bos2_0.Service.FixedAreaService;
import com.zhangck.bos2_0.dao.CourierRepository;
import com.zhangck.bos2_0.dao.FixedAreaRepoistory;
import com.zhangck.bos2_0.dao.TakeTimeRepository;

import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.domain.base.FixedArea;
import cn.itcast.bos.domain.base.TakeTime;
import cn.itcast.crm.domain.Customer;

/** 
* @author 上午茶
* @version 创建时间：2018年5月31日 下午1:23:20 
* 类说明 
*/
@Service
@Transactional
public class FixedAreaServiceImpl  implements FixedAreaService{

	@Autowired
	private FixedAreaRepoistory fixedAreaServiceImpl;
	
	@Override
	public void save(FixedArea model) {
		fixedAreaServiceImpl.save(model);
	}

	@Override
	public Page<FixedArea> findPageData(Specification<FixedArea> specification, Pageable request) {
		return fixedAreaServiceImpl.findAll(specification, request);
	}
	@Autowired
	private CourierRepository courierRepository;

	@Autowired
	private TakeTimeRepository takeTimeRepository;
	@Override
	public void associationCourierToFixedArea(FixedArea model, Integer courierId, Integer takeTimeId) {
		FixedArea fixedArea = fixedAreaServiceImpl.findOne(model.getId());
	    Courier courier = courierRepository.findOne(courierId);
	    TakeTime takeTime = takeTimeRepository.findOne(takeTimeId);
	    //将快递员关联到定区上
	    fixedArea.getCouriers().add(courier);
	
	    //将收派时间关联到快递员上
	    courier.setTakeTime(takeTime);
	}

	@Override
	public List<Integer> CourierToFixedArea_association(String parameter) {
		return courierRepository.findByCourierID(parameter);
	}

	@Override
	public List<Courier> finCouries(Iterable<Integer> couriersId) {
		return courierRepository.findByCourierIDAll(couriersId);
	}

}
